import 'package:flutter/material.dart';

class OffstageDemo extends StatefulWidget {
  OffstageDemo({Key key}) : super(key: key);

  @override
  _OffstageDemoState createState() => _OffstageDemoState();
}

class _OffstageDemoState extends State<OffstageDemo> {
  String showText = "hide";
  bool isOff = false;
  void onButtonClickListener() {
    setState(() {
      isOff = !isOff;
    });
    if (isOff) {
      showText = "show";
    } else {
      showText = "hide";
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('OffstageDemo'),
      ),
      body: Container(
        margin: EdgeInsets.only(top: 50.0),
        child: Offstage(
          offstage: isOff,
          child: Container(
            color: Colors.red,
            child: Text("Offstage组件"),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: onButtonClickListener,
        child: Text(showText),
      ),
    );
  }
}
